/*
 * calibration_callback.c
 *
 *  Created on: 2022年02月10日
 *      Author: Moon
 */


/* Includes ------------------------------------------------------------------*/
#include "ParmManage.h"
#include "cmd_process.h"
#include "pfc_task.h"
#include "system.h"
#include "main_task.h"

/* Private defines -----------------------------------------------------------*/

/* Public enum    -----------------------------------------------------------*/

/* Public Struct  -----------------------------------------------------------*/


/* Private Variable  ---------------------------------------------------------*/
//Pointer

//Array

//Const

/* Private function prototypes -----------------------------------------------*/


/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_mode_callback(user_packet_t *user)
{
	ack_packet_t *ack;
    
    if(user->style == CMD_READ)       //读取
    {
        // 应答返回数据
        ack = Ack_Malloc(1);
		//ack->data[0] = pfcCtrl.devState;
    }
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_process_callback(user_packet_t *user)
{
	#if 0
	ack_packet_t *ack;

	if (user->style == CMD_SET) //设置
	{
		// 用户数据处理
		memcpy(&pfcCtrl.experiType.airPre, &user->data[0], 1);
		memcpy(&pfcCtrl.experiType.cailVac, &user->data[1], 1);
		memcpy(&pfcCtrl.experiType.normalTCail, &user->data[2], 1);
		memcpy(&pfcCtrl.experiType.coldTCail, &user->data[3], 1);
		memcpy(&pfcCtrl.experiType.adsorVac, &user->data[4], 1);
		memcpy(&pfcCtrl.experiType.adsorb, &user->data[5], 1);
		memcpy(&pfcCtrl.experiType.backFill, &user->data[6], 1);
		// 应答返回数据
		ack = Ack_Malloc(1);
		ack->data[0] = 0x00;
	
	}
	else if (user->style == CMD_READ) //读取
	{
		// 应答返回数据
		ack = Ack_Malloc(7);
		ack->data[0] = pfcCtrl.experiType.airPre;
		ack->data[1] = pfcCtrl.experiType.cailVac;
		ack->data[2] = pfcCtrl.experiType.normalTCail;
		ack->data[3] = pfcCtrl.experiType.coldTCail;
		ack->data[4] = pfcCtrl.experiType.adsorVac;
		ack->data[5] = pfcCtrl.experiType.adsorb;
		ack->data[6] = pfcCtrl.experiType.backFill;
	}
	return ack;
	#endif
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_devtime_callback(user_packet_t *user)
{
	#if 0
	ack_packet_t *ack;
    
	// 应答返回数据
	ack = Ack_Malloc(192);
	memcpy(&ack->data[0], &g_glpCnt, sizeof(uint64_t));  //没有参数
	memcpy(&ack->data[8], &g_glpCnt, sizeof(uint64_t));
	memcpy(&ack->data[16], &g_glpCnt, sizeof(uint64_t));
	
	return ack;
	#endif
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_readadc_callback(user_packet_t *user)
{
	#if 0
	ack_packet_t *ack;
    
	// 应答返回数据
	ack = Ack_Malloc(4);
	memcpy(&ack->data[0], &g_glpCnt, sizeof(uint64_t));  //暂无接口
	
	return ack;
	#endif
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_setdac_callback(user_packet_t *user)
{
	ack_packet_t *ack;
    
	// 用户数据处理
	//memcpy(&pfcCtrl.experiType.airPre, &user->data[0], 2);

	// 应答返回数据
	ack = Ack_Malloc(1);
	ack->data[0] = 0x00;
	
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_cmd_callback(user_packet_t *user)
{
//	ack_packet_t *ack;

//	if (user->style == CMD_SET) //设置
//	{
//		// 用户数据处理
//		memcpy(&pfcCtrl.runCtrl, &user->data[0], 1);
//		// 应答返回数据
//		ack = Ack_Malloc(1);
//		ack->data[0] = 0x00;
//	}
//	else if (user->style == CMD_READ) //读取
//	{
//		// 应答返回数据
//		ack = Ack_Malloc(1);
//		ack->data[0] = pfcCtrl.runCtrl;
//	}
//	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    0x00(stop);0x01(move up);0x02(move down)
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_motor_callback(user_packet_t *user)
{
	ack_packet_t *ack;
	uint8_t st;
	if (user->style == CMD_SET) //设置
	{
		// 用户数据处理
		data_server.motor_st_set(&data_server, user->data[0]);
		// 应答返回数据
		ack = Ack_Malloc(1);
		ack->data[0] = 0x00;
	}
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_readmotor_callback(user_packet_t *user)
{
	ack_packet_t *ack;
    
	// 应答返回数据
	ack = Ack_Malloc(1);
	ack->data[0] = data_server.motor_st_get(&data_server);
	
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_backfill_callback(user_packet_t *user)
{

	ack_packet_t *ack;
	uint8_t st;
	if (user->style == CMD_SET) //设置
	{
		st = user->data[0];
        
        // 用户数据处理
		data_server.isStartBackfill = (st == 0x01 ? true:false);
		
        // 应答返回数据
		ack = Ack_Malloc(1);
		ack->data[0] = 0x00;
	}
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_motorspeed_callback(user_packet_t *user)
{
	ack_packet_t *ack;

	if (user->style == CMD_SET) //设置
	{
		// 用户数据处理
		//memcpy(&pfcCtrl.runCtrl, &user->data[0], 1);
		// 应答返回数据
		ack = Ack_Malloc(1);
		ack->data[0] = 0x00;
	}
	else if (user->style == CMD_READ) //读取
	{
		// 应答返回数据
		ack = Ack_Malloc(1);
		//ack->data[0] = pfcCtrl.runCtrl;
	}
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_led_seterror_callback(user_packet_t *user)
{
	ack_packet_t *ack;
	uint8_t color_red = 1;

	if (user->style == CMD_SET) //设置
	{
		data_server.expand_led_prestate_get(&data_server,user->data[0]);

		// 用户数据处理 
		data_server.led_control_flag = true;
		data_server.expand_led_set(color_red, user->data[0]);        
		// 应答返回数据
		ack = Ack_Malloc(1);
		ack->data[0] = 0x00;
	}
	return ack;
}

/***********************************************************************************
 * @brief
 * ex:
 * @par    None
 * @retval None
 **********************************************************************************/
ack_packet_t *ctrl_led_restore_callback(user_packet_t *user)
{
	ack_packet_t *ack;

	if (user->style == CMD_SET) //设置
	{
    // 用户数据处理 
		data_server.led_control_flag = false;
		data_server.expand_led_restore(&data_server,user->data[0]);        
		// 应答返回数据
		ack = Ack_Malloc(1);
		ack->data[0] = 0x00;
	}
	return ack;
}

#if 0
//扩展led 测试接口
static int expand_led_test(uint8_t argc, char **argv)
{
    if (argc >= 2)
    {
        if (!strcmp(argv[1], "error"))
        {
            if (argc >= 3)
            {
                uint8_t led_num = strtoul(argv[2], NULL, 10);
                
                data_server.expand_led_prestate_get(&data_server);

                // 用户数据处理 
                data_server.led_control_flag = true;
                data_server.expand_led_set(1, led_num);      
                
                Ashell_print("led error set completed.\r\n");
            }
            else
            {
                Ashell_print("Please input ex_led error <led_num>.\r\n");
            }
        }
        else if (!strcmp(argv[1], "restore"))
        {
            if (argc >= 2)
            {
                data_server.led_control_flag = false;
                data_server.expand_led_restore(&data_server);       
            }
            else
            {
                Ashell_print("Please input flash <read addr length>.\r\n");
            }
        }

    }
    else
    {
        Ashell_print("Please input ex_led <operation>.\r\n");
    }
    return 1;
}


SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), ex_led, expand_led_test, expand_led operation testing);
#endif
/******************* (C) COPYRIGHT 2021 CIQTEK Samuel *****END OF FILE****/

